home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 2.7 KB | 113 lines |
- /**
- * An abstract class to implement the functionality associated with
- * a "roll over button." The basic behavior is such that when the mouse
- * is "rolled over" the button, the button reacts by displaying a
- * different image to give instant feedback to the user.
- */
- public abstract class RolloverButton extends ImageButton
- {
- //Declare data members
- //Insert "RolloverButton data members"
- protected String upImage;
- protected String downImage;
- protected String rolloverImage;
-
- /**
- * Constructs a default instance of this class.
- */
- public RolloverButton()
- {
- //Initialize the state of the button
- //Insert "RolloverButton init state"
- upImage = "up";
- downImage = "down";
- rolloverImage = "rollover";
- initImages();
- setImage(upImage);
- }
-
- /**
- * Sub classes need to define this to handle initializing their
- * images, and state information.
- */
- protected abstract void initImages();
-
- /**
- * Sets the button to be in the correct configuration for the
- * current state.
- */
- public void refreshImage()
- {
- //Handle determining the current state, and reacting appropriately
- //Insert "RolloverButton refreshImage"
- if (isMouseInside)
- {
- if (isMouseDown)
- {
- setImage(downImage);
- }
- else
- {
- setImage(rolloverImage);
- }
- }
- else
- {
- setImage(upImage);
- }
- }
-
- /**
- * Gets called when the mouse button is pressed on this button.
- */
- protected void handleMousePressed()
- {
- //Set the image to the appropriate image for a mouse press.
- //Insert "RolloverButton mousePressed"
- setImage(downImage);
- }
-
- /**
- * Gets called when the mouse button is released on this button.
- * @param isMouseInside, if true, the mouse is located inside the button area,
- * if false the mouse is outside the button area.
- */
- protected void handleMouseRelease(boolean isMouseInside)
- {
- //Set the image to the appropriate image for a mouse release,
- //and calls the super classes version to include inherited functionality.
- //Insert "RolloverButton mouseReleased"
- if (isMouseInside)
- {
- setImage(rolloverImage);
- }
- super.handleMouseRelease(isMouseInside);
- }
-
- /**
- * Gets called when the mouse crosses into or out of the button area.
- * @param isMouseInside, is true if the mouse is in the button area,
- * false if it is outside.
- * @param isMouseDown, is true if the mouse button is pressed, false if it is not.
- */
- protected void handleRollover(boolean isMouseInside, boolean isMouseDown)
- {
- //Handle determining the current state, and reacting appropriately
- //Insert "RolloverButton handleRollover"
- if (isMouseInside)
- {
- if (isMouseDown)
- {
- setImage(downImage);
- }
- else
- {
- setImage(rolloverImage);
- }
- }
- else
- {
- setImage(upImage);
- }
- }
- }